package com.example.tests;

import java.util.Random;

import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
import static org.hamcrest.Matchers.equalTo;
import com.example.fw.Contacts;


public class ContactModificationTests extends TestBase {
	
	private int index;

	@Test(dataProvider = "randomContacts")
	public void ContactWillBeModification(ContactObject validContact) throws Exception {
        Contacts oldList = app.getContactHelper().getContacts();
        if (oldList.size() == 0)
        	index = new Random().nextInt(oldList.size());
        	ContactObject contactModification = app.getContactHelper().getContact(index);
        	app.getContactHelper().modifyContact(index, validContact);
        	Contacts newList = app.getContactHelper().getContacts();
        	ContactObject contactChangeModification = app.getContactHelper().getContact(index);
        	assertThat(newList, equalTo(oldList.without(contactModification).withAdded(contactChangeModification)));
	}
}